#pragma once

#include <iostream>
#include <sys/epoll.h>
#include <unistd.h>

class Epoll
{
public:
    static const int gsize = 256;

    static int CreateEpoll()
    {
        int epfd = epoll_create(gsize);
        if (epfd > 0) return epfd;
        exit(5);
    }

    static bool CtlEpoll(int epfd, int oper, int sock, uint32_t events)
    {
        struct epoll_event ev;
        ev.events = events;
        ev.data.fd = sock;
        int n = epoll_ctl(epfd, oper, sock, &ev);
        return n == 0;
    }

    static int WaitEpoll(int epfd, struct epoll_event* revs, int num, int timeout)
    {
        // 细节一: 如果底层就绪的recv很多,revs装不下怎么办？ 装不下,下来再来拿    这里就相当于是用revs来拿走就绪的fd
        // 细节二: epoll_wait这里是有多少个就绪,他就给你返回就绪的个数,并将就绪的events按照顺序放入revs数组中
        return epoll_wait(epfd, revs, num, timeout);
    }
};
